package com.example.hbasespringbootdemo;

import com.example.hbasespringbootdemo.service.CityService;
import com.example.hbasespringbootdemo.utils.HbaseUtils;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

@SpringBootApplication
public class HbaseSpringbootDemoApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(HbaseSpringbootDemoApplication.class, args);
    }

    @Autowired
    private HbaseUtils hbaseUtils;

    @Override
    public void run(String... args) throws Exception {
        int hello = hbaseUtils.createTable("hello", new String[]{"info", "grade"});
        hbaseUtils.insert("hello", "row002, row003, row004", "info", "id", "5");
        hbaseUtils.insert("hello", "row002, row003, row004", "info", "name", "lsh");
        hbaseUtils.insert("hello", "row002, row003, row004", "info", "age", "27");
        Result result = hbaseUtils.queryByRow("hello", "row002, row003, row004");
        List<KeyValue> values = result.list();
        System.out.println("COLUMN\t\t\tCELL");
        for (KeyValue value : values) {
            System.out.print(new String(value.getFamily()) + ":");
            System.out.print(new String(value.getQualifier()) + "\t\t");
            System.out.print(new String(value.getValue()) + ",");
            System.out.println("timestamp = " + value.getTimestamp());
        }
    }
}
